package com.fengdi.solutions.esay;

import com.fengdi.publicObject.TreeNode;

/**
 * @Description leetcode第222题：完全二叉树的节点个数
 * @author FengDi
 * @Solution dfs深度优先遍历
 * */


public class _222_Complete_binary_tree {
    private int counter = 0;
    public int countNodes(TreeNode root) {
        this.dfs(root);
        return this.counter;
    }

    private void dfs(TreeNode root) {
        if(root == null) return;
        this.counter++;
        this.dfs(root.left);
        this.dfs(root.right);
    }
}
